/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cput.tp.patterns.structural.compositepattern;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Malotana
 */
public class Composite implements Component{
    List<Component>components = new ArrayList<Component>();
    @Override
    public void sayHello() {
        for(Component componet : components)
        {
            componet.sayHello();
        }  
    }

    @Override
    public void sayGoodBye() {
      for(Component component:components){
            component.sayGoodBye();
           }
         }
    
    
    public void add(Component component){
      components.add(component);  
    }

    public void remove(Component component){
        components.remove(component);
    }

    public List<Component> getComponents(){
        return components;
    }

    public Component getCompnent(int index){
        return components.get(index);
    }
}
